<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="主键id" prop="id" v-if="dataForm.id">
        <el-input v-model="dataForm.id" placeholder="主键id" disabled></el-input>
    </el-form-item>
    <el-form-item label="所属党组织" prop="partyOrganization">
        <el-input v-model="dataForm.partyOrganization" placeholder="所属党组织"></el-input>
    </el-form-item>
    <el-form-item label="党组织code" prop="code">
        <el-input v-model="dataForm.code" placeholder="党组织code"></el-input>
    </el-form-item>
    <el-form-item label="姓名" prop="fullName">
        <el-input v-model="dataForm.fullName" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="身份证号码" prop="cardNo">
        <el-input v-model="dataForm.cardNo" placeholder="身份证号码"></el-input>
    </el-form-item>
    <el-form-item label="手机号码" prop="phoneNo">
        <el-input v-model="dataForm.phoneNo" placeholder="手机号码"></el-input>
    </el-form-item>
    <el-form-item label="交纳党费" prop="payPartyDues">
        <el-input v-model="dataForm.payPartyDues" placeholder="交纳党费"></el-input>
    </el-form-item>
    <el-form-item label="性别 0-男 1-女" prop="gender">
        <el-input v-model="dataForm.gender" placeholder="性别 0-男 1-女"></el-input>
    </el-form-item>
    <el-form-item label="年龄" prop="age">
        <el-input v-model="dataForm.age" placeholder="年龄"></el-input>
    </el-form-item>
    <el-form-item label="党龄" prop="partyAge">
        <el-input v-model="dataForm.partyAge" placeholder="党龄"></el-input>
    </el-form-item>
    <el-form-item label="学历" prop="education">
        <el-input v-model="dataForm.education" placeholder="学历"></el-input>
    </el-form-item>
    <el-form-item label="参加工作时间" prop="workingTime">
        <el-input v-model="dataForm.workingTime" placeholder="参加工作时间"></el-input>
    </el-form-item>
    <el-form-item label="名族" prop="nation">
        <el-input v-model="dataForm.nation" placeholder="名族"></el-input>
    </el-form-item>
    <el-form-item label="出生年月" prop="birthday">
        <el-input v-model="dataForm.birthday" placeholder="出生年月"></el-input>
    </el-form-item>
    <el-form-item label="入党年月" prop="joinDate">
        <el-input v-model="dataForm.joinDate" placeholder="入党年月"></el-input>
    </el-form-item>
    <el-form-item label="专业" prop="major">
        <el-input v-model="dataForm.major" placeholder="专业"></el-input>
    </el-form-item>
    <el-form-item label="任职单位" prop="employer">
        <el-input v-model="dataForm.employer" placeholder="任职单位"></el-input>
    </el-form-item>
    <el-form-item label="最后交费时间" prop="lastPaymentDate">
        <el-input v-model="dataForm.lastPaymentDate" placeholder="最后交费时间"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime" v-if="dataForm.id">
        <el-input v-model="dataForm.createTime" placeholder="创建时间" disabled></el-input>
    </el-form-item>
    <el-form-item label="创建人" prop="createBy" v-if="dataForm.id">
        <el-input v-model="dataForm.createBy" placeholder="创建人" disabled></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="updateTime" v-if="dataForm.id">
        <el-input v-model="dataForm.updateTime" placeholder="创建时间" disabled></el-input>
    </el-form-item>
    <el-form-item label="更新人" prop="updateBy" v-if="dataForm.id">
        <el-input v-model="dataForm.updateBy" placeholder="更新人" disabled></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/srsbbulletinpartymember'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          id: 0,
          partyOrganization: '',
          code: '',
          fullName: '',
          cardNo: '',
          phoneNo: '',
          payPartyDues: '',
          gender: '',
          age: '',
          partyAge: '',
          education: '',
          workingTime: '',
          nation: '',
          birthday: '',
          joinDate: '',
          major: '',
          employer: '',
          lastPaymentDate: '',
          createTime: '',
          createBy: '',
          updateTime: '',
          updateBy: ''
        },
        dataRule: {
          partyOrganization: [
            { required: true, message: '所属党组织不能为空', trigger: 'blur' }
          ],
          code: [
            { required: true, message: '党组织code不能为空', trigger: 'blur' }
          ],
          fullName: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          cardNo: [
            { required: true, message: '身份证号码不能为空', trigger: 'blur' }
          ],
          phoneNo: [
            { required: true, message: '手机号码不能为空', trigger: 'blur' }
          ],
          payPartyDues: [
            { required: true, message: '交纳党费不能为空', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '性别 0-男 1-女不能为空', trigger: 'blur' }
          ],
          age: [
            { required: true, message: '年龄不能为空', trigger: 'blur' }
          ],
          partyAge: [
            { required: true, message: '党龄不能为空', trigger: 'blur' }
          ],
          education: [
            { required: true, message: '学历不能为空', trigger: 'blur' }
          ],
          workingTime: [
            { required: true, message: '参加工作时间不能为空', trigger: 'blur' }
          ],
          nation: [
            { required: true, message: '名族不能为空', trigger: 'blur' }
          ],
          birthday: [
            { required: true, message: '出生年月不能为空', trigger: 'blur' }
          ],
          joinDate: [
            { required: true, message: '入党年月不能为空', trigger: 'blur' }
          ],
          major: [
            { required: true, message: '专业不能为空', trigger: 'blur' }
          ],
          employer: [
            { required: true, message: '任职单位不能为空', trigger: 'blur' }
          ],
          lastPaymentDate: [
            { required: true, message: '最后交费时间不能为空', trigger: 'blur' }
          ],
        }
      }
    },
    methods: {
      init (id) {
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            if (id) {
            getObj(id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      },
      //重置表单
      closeDialog() {
          this.$refs["dataForm"].resetFields()
      }
    }
  }
</script>
